package file;

import java.awt.datatransfer.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class FileTransferable implements Transferable {
    private File file;

    public FileTransferable(File file) {
        this.file = file;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[]{DataFlavor.javaFileListFlavor};
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return DataFlavor.javaFileListFlavor.equals(flavor);
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if (isDataFlavorSupported(flavor)) {
            return Arrays.asList(file);
        }
        throw new UnsupportedFlavorException(flavor);
    }
}